<template>
  <el-dialog title="商品价格组详情" :close-on-click-modal="false" :visible.sync="visible" center>
		<el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form :model="dataForm" ref="dataForm" label-width="80px">
      <el-form-item label="商品" prop="goodsName">
        <el-input v-model="dataForm.goodsName" placeholder="商品">
          <el-button slot="append" @click="selectGoods">选择</el-button>
        </el-input>
      </el-form-item>
      <el-form-item label="价格组" prop="priceGroupId">
        <el-select v-model="dataForm.priceGroupId">
          <el-option v-for="item in priceGroupOptions" :key="item.value" :value="item.value" :label="item.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="税率" prop="taxRate">
        <el-input v-model="dataForm.taxRate" placeholder="税率"></el-input>
      </el-form-item>
      <el-form-item label="含税价格" prop="taxPrice">
        <el-input v-model="dataForm.taxPrice" placeholder="含税价格"></el-input>
      </el-form-item>
      <el-form-item label="不含税价格(含税价格-税率)" prop="notTaxPrice">
        <el-input v-model="dataForm.notTaxPrice" placeholder="不含税价格(含税价格-税率)"></el-input>
      </el-form-item>
      <el-form-item label="零售价格" prop="price">
        <el-input v-model="dataForm.price" placeholder="零售价格"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="memo">
        <el-input v-model="dataForm.memo" placeholder="备注"></el-input>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
  import { goodsPriceGetObj, goodsPriceAddObj, goodsPricePutObj } from '@/api/eims/goods-price.js'
  import { priceGroupFetchList } from '@/api/eims/price-group.js'

  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          id: 0,
          goodsId: '',
          goodsName: '',
          priceGroupId: '',
          taxRate: '',
          taxPrice: '',
          notTaxPrice: '',
          price: '',
          memo: '',
          status: '1'
        },
        priceGroupOptions: []
      }
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.getPriceGroupList()
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            goodsPriceGetObj(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        })
      },
      // 获取价格组列表
      getPriceGroupList () {
        priceGroupFetchList().then(result => {
          let resultData = result.data.data.records
          let list = []
          resultData.forEach(item => {
            list.push({value: item.id,name:item.groupName})
          })
          this.priceGroupOptions = list
        })
      }
    }
  }
</script>
